home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.5 Applications 2002 November / SGI IRIX 6.5 Applications 2002 November.iso / dist / gateway.idb / usr / WebFace / Source / 50-CommHardware / modem / modem-account.frm.z / modem-account.frm
Encoding:
Text File  |  2002-06-12  |  11.1 KB  |  399 lines

  1. #!/usr/bin/perl5
  2. #
  3. # modem-accounts.cgi
  4. #
  5. # Copyright 1988-1996 Silicon Graphics, Inc.
  6. # All rights reserved.
  7. #
  8. # This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  9. # the contents of this file may not be disclosed to third parties, copied or
  10. # duplicated in any form, in whole or in part, without the prior written
  11. # permission of Silicon Graphics, Inc.
  12. #
  13. # RESTRICTED RIGHTS LEGEND:
  14. # Use, duplication or disclosure by the Government is subject to restrictions
  15. # as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  16. # and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  17. # successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  18. # rights reserved under the Copyright Laws of the United States.
  19. #
  20. # $Id: modem-account.frm,v 1.41 1997/11/17 19:08:47 shotes Exp $
  21.  
  22. require "/usr/OnRamp/lib/OnRamp.pm";
  23. require "/usr/OnRamp/lib/java.pm";
  24.  
  25. $conf = "/etc/uucp/Systems";
  26. $dummy = "/etc/uucp/Systems.temp";
  27. $myname = "modem-account.cgi";
  28. $help_page = "modem-account-help.html";
  29. $title = "Modem Accounts";
  30.  
  31. $js_main = "
  32. type = \"account\";
  33. $js_account_main
  34. $js_error_box
  35. $js_help
  36. $js_meta
  37. function testAdd(form) {
  38.     if (!testMeta(form.nme, \"account name\")) return (false);
  39.     return (true);
  40. }";
  41.  
  42. $js_add =
  43. "$js_account_add
  44. $js_error_box
  45. $js_help
  46. $js_phone
  47. $js_meta
  48. function testAdd(form) {
  49.     if (!testPhone(form.phone)) return (false);
  50.     if (!testMeta(form.login,\"login name\")) return (false);
  51.     if (!testMeta(form.password,\"login password\")) return (false);
  52.     return (true);
  53. }";
  54.  
  55.  
  56. $js_edit = 
  57. "$js_account_edit
  58. $js_error_box
  59. $js_help
  60. $js_phone
  61. $js_meta
  62. function testEdit(form) {
  63.     if (!testMeta(form.nme,\"remote host name\")) return (false);
  64.     if (!testPhone(form.phone)) return (false);
  65.     if (!testMeta(form.login,\"login name\")) return (false);
  66.     if (!testMeta(form.password,\"password\")) return (false);
  67.     return (true);
  68. }";
  69.  
  70. print "Content-type: text/html\n\n";
  71.  
  72. &get_fields;
  73.  
  74. &getAccounts;
  75.  
  76. if (%fld) {
  77.     $help = $document_root . $ENV{"SCRIPT_NAME"};
  78.     $help =~ s/cgi$/hlp/;
  79.     exec $help if ($fld{'help'} eq "Help");
  80.  
  81.     $fld{'phone'} =~ s/-//g;
  82.     $fld{'phone'} =~ s/\(//g;
  83.     $fld{'phone'} =~ s/\)//g;
  84.     $fld{'phone'} =~ s/,//g;
  85.     $fld{'chosen'} =~ /([\w.-]+)/;
  86.     $fld{'chosen'} = $1;
  87. }
  88.  
  89. if ($fld{'add'}) { 
  90.     &formValid_add;
  91.     $val{'nme'} = $fld{'nme'}; 
  92.     &addAccount; 
  93. }
  94. elsif ($fld{'delete'}) { 
  95.     &error(2,"To delete an existing account, first select an account from
  96.     list, then click the delete button.") if !$fld{'chosen'};
  97.     $message = qq|Click "Ok" to save changes.|; 
  98.     &generic($fld{'chosen'}); 
  99. }
  100. elsif ($fld{'edit'}) { 
  101.     &error(2,"To edit an existing account, first select an account from
  102.     list, then click the edit button.") if !$fld{'chosen'};
  103.     &putEdit; 
  104.     &editAccount; 
  105. }
  106. elsif ($fld{'doedit'}) { &formValid_doedit; &doEdit; &getAccounts; &generic; }
  107. elsif ($fld{'doit'}) {
  108.     &tryToDelete; 
  109.     &getAccounts; 
  110.     if (!$message) { $message = "No changes made."; }
  111.     &generic; 
  112. }
  113. elsif ($fld{'doadd'}) { &formValid_doadd; &doAdd; &getAccounts; &generic; }
  114. else {
  115.     if (%fld) { $val{'nme'} = $fld{'nme'}; $message = qq|Use buttons to submit form.|; } 
  116.     &generic; 
  117. }
  118.  
  119. sub formValid_add {
  120.     &error(2,"Account name required.") if !$fld{'nme'};
  121.     &error(2,"Invalid account name.") if &deluxeError($fld{'nme'});
  122. }
  123.  
  124. sub formValid_doadd {
  125.     &error(0,"Invalid phone number.") if !$fld{'phone'} || &check_phone($fld{'phone'});
  126.     &error(0,"Invalid login name.") if &deluxeError($fld{'login'});
  127.     &error(0,"Invalid password.") if &deluxeError($fld{'password'});
  128. }
  129.  
  130.  
  131. sub formValid_doedit {
  132.     &error(1,"Invalid remote host name.") if &deluxeError($fld{'nme'});
  133.     &error(1,"Invalid phone number.") if !$fld{'phone'} || &check_phone($fld{'phone'});
  134.     &error(1,"Invalid login name.") if &deluxeError($fld{'login'});
  135.     &error(1,"Invalid password.") if &deluxeError($fld{'password'});
  136. }
  137.  
  138. sub deluxeError {
  139.     return 1 if length($_[0]) > 8;
  140.     return 1 if $_[0] =~ /$METACHARS/o;
  141.     return 1 if $_[0] =~ /\s/;
  142.     0;
  143. }
  144.  
  145. sub error {
  146.     &error_block($_[1]);
  147.     %val = %fld;
  148.     if ($_[0] == 0) { &addAccount; }
  149.     elsif ($_[0] == 1) { &editAccount; }
  150.     else { &generic; }
  151.     exit 0;
  152. }
  153.  
  154. sub doEdit {
  155.     open(IN,"< $conf");
  156.     open(OUT,"> $dummy");
  157.     $found = 0;
  158.     while(<IN>) {
  159.     $line = $_;
  160.     if ($line =~ /^\s*\#/) { print OUT $line; next; }
  161.     $line =~ /^\s*(.*)$/;
  162.     $line1 = $1;
  163.     @items = split(/\s+/,$line1);
  164.     if ($items[2] eq "ACU" && $items[0] eq $fld{'chosen'}) {
  165.         print OUT "# $line";
  166.         if ($found == 0) {
  167.         $found = 1;
  168.         print OUT "$fld{'nme'} Any ACU $fld{'speed'} $fld{'phone'}";
  169.         print OUT " in:--in: $fld{'login'}";
  170.         if ($fld{'password'}) { print OUT " word: $fld{'password'}"; }
  171.         print OUT "\n";
  172.         }
  173.     } else { print OUT $line; }
  174.     }
  175.     if ($found == 0) {
  176.     print OUT "$fld{'nme'} Any ACU $fld{'speed'} $fld{'phone'}";
  177.     print OUT " in:--in: $fld{'login'}";
  178.     if ($fld{'password'}) { print OUT " word: $fld{'password'}"; }
  179.     print OUT "\n";
  180.     }
  181.     close(IN);
  182.     close(OUT);    
  183.     chmod 0600, $conf;
  184.     rename($dummy,$conf);
  185.     chmod 0400, $conf;
  186.  
  187.     $message = "Account edited.";
  188. }    
  189.  
  190. sub clear {
  191.     open(OUT_0,"> $_[0]");
  192.     close(OUT_0);
  193. }
  194.  
  195. sub putEdit {
  196.     $num = -1;
  197.     for ($i=0;$i<$number;$i++) {
  198.     if ($nme[$i] eq $fld{'chosen'}) { $num = $i; }
  199.     }
  200.  
  201.     $val{'nme'} = $nme[$num];
  202.     $val{'phone'} = $phone[$num];
  203.     $val{'login'} = $login[$num];
  204.     $val{'password'} = $password[$num];
  205.     $val{'speed'} = $speed[$num];
  206. }
  207.  
  208. sub editAccount {
  209.     &js_title_block($title, $js_edit);
  210.     &header_block("Edit Modem Account");
  211.  
  212.     print "<form name=EditForm action=$myname method=post onSubmit=\"return runSubmit()\">";
  213.  
  214.     print qq|<input type=hidden name="chosen" value=$fld{'chosen'}>|;
  215.  
  216.     print "<center><table cellpadding=5 width=450>";
  217.  
  218.     print "<tr><th align=left>Remote host name:</th><th align=left>",
  219.       &text('nme',$val{'nme'}, 20),"</th></tr>";
  220.  
  221.     print "<tr><th align=left>Phone number:</th><th align=left>",
  222.       &text('phone',$val{'phone'}, 20),"</th></tr>";
  223.  
  224.     print "<tr><th align=left>Login name:</th><th align=left>",
  225.       &text('login',$val{'login'}, 20),"</th></tr>";
  226.  
  227.     print "<tr><th align=left>Password:</th><th align=left>",
  228.       &text('password',"$val{'password'}", 20),"</th></tr>";   
  229.  
  230.     print "<tr><th align=left>Baud rate:</th><th align=left>",
  231.       &select('speed',$val{'speed'},
  232.       '2400','9600','14400','19200','28800', '38400'),"</th></tr>";
  233.  
  234.     print "</table></center><br>";
  235.  
  236.     print &js_buttons('doedit','Ok','onClick="markEdit()"',
  237.     'onClick="markOther()"',
  238.     "onClick=\"do_help('$help_page'); return (false)\"");
  239.  
  240.     print "</form></body></html>";
  241. }
  242.     
  243. sub tryToDelete {
  244.     $account = $fld{'toDelete'};
  245.     if (!$account) { return 0; }
  246.  
  247.     open(IN,"< $conf");
  248.     open(OUT,"> $dummy");
  249.     while(<IN>) {
  250.     $line = $_;
  251.     if ($line =~ /^\s*\#/) { print OUT $line; next; }
  252.     $line =~ /^\s*(.*)$/;
  253.     $line1 = $1;
  254.     @items = split(/\s+/,$line1);
  255.     if ($items[2] eq "ACU" && $items[0] eq $account) {
  256.         print OUT "# $line";
  257.     } else { print OUT $line; }
  258.     }
  259.     close(IN);
  260.     close(OUT);
  261.     chmod 0600, $conf;
  262.     rename($dummy,$conf);
  263.     chmod 0400, $conf;
  264.  
  265.     $message = "Account deleted.";    
  266. }
  267.  
  268. sub doAdd {
  269.     chmod 0600, $conf;
  270.     open(OUT,">> $conf");
  271.     print OUT "$fld{'nme'} Any ACU $fld{'speed'} $fld{'phone'} in:--in:";
  272.     print OUT " $fld{'login'}";
  273.     if ($fld{'password'}) { print OUT " word: $fld{'password'}"; }
  274.     print OUT "\n";
  275.     close(OUT);
  276.     chmod 0400, $conf;
  277.  
  278.     $message = "New account added.";
  279. }
  280.  
  281. sub addAccount {
  282.     &js_title_block($title, $js_add);
  283.     &header_block("Add New Modem Account");
  284.  
  285.     print "<form name=AddForm action=$myname method=post onSubmit=\"return runSubmit()\">\n";
  286.  
  287.     print "<center><table cellpadding=5 width=450>\n";
  288.  
  289.     print "<input type=hidden name=nme value=$val{'nme'}>\n";
  290.  
  291.     print "<tr><th align=left>Remote host name:</th><td><tt>",
  292.       $val{'nme'},"</tt></td></tr>\n";
  293.  
  294.     print "<tr><th align=left>Phone number:</th><th align=left>",
  295.       &text('phone',"$val{'phone'}",20),"</th></tr>\n";
  296.  
  297.     print "<tr><th align=left>Login name:</th><th align=left>",
  298.       &text('login',"$val{'login'}",20),"</th></tr>\n";
  299.  
  300.     print "<tr><th align=left>Password:</th><th align=left>",
  301.       &text('password',"$val{'password'}",20),"</th></tr>\n";
  302.  
  303.     print "<tr><th align=left>Baud rate:</th><th align=left>",
  304.       &select('speed',$val{'speed'},
  305.       '2400','9600','14400','19200','28800', '38400'),"</th></tr>";
  306.  
  307.     print "</table></center><br>";
  308.  
  309.     print &js_buttons('doadd','Ok','onClick="markAdd()"',
  310.         'onClick="markOther()"',
  311.         "onClick=\"do_help('$help_page'); return (false)\"");
  312.  
  313.     print "</form></body></html>";
  314. }
  315.  
  316. sub getAccounts {
  317.     $i = 0;
  318.     open(IN,"< $conf");
  319.     while(<IN>) {
  320.     $line = $_;
  321.     if ($line =~ /^\s*\#/) { next; }
  322.     $line =~ /^\s*(.*)$/;
  323.     $line1 = $1;
  324.     @items = split(/\s+/,$line1);
  325.     if ($items[2] eq "ACU") {
  326.         $nme[$i] = $items[0];
  327.         $speed[$i] = $items[3];
  328.         $phone[$i] = $items[4];
  329.         for ($j=5;$j<$#items;$j++) {
  330.         if (substr($items[$j],length($items[$j])-3,3) eq 'in:') 
  331.             { $login[$i] = $items[$j+1]; }
  332.         if (substr($items[$j],length($items[$j])-3,3) eq 'rd:') 
  333.             { $password[$i] = $items[$j+1]; }
  334.         }
  335.         $i++;
  336.     }
  337.     }
  338.     $number = $i;
  339.     close(IN);
  340. }
  341.     
  342.  
  343. sub generic {
  344.     &js_title_block($title, $js_main);
  345.     &header_block($title);
  346.  
  347.     if (!$number && !$message) { $message = "No existing modem accounts."; }
  348.     print "<i>$message</i>";
  349.  
  350.     print "<form name=AccountForm action=$myname method=post onSubmit=\"return runSubmit()\">\n";
  351.  
  352.     if($_[0]) { print "<input type=hidden name=toDelete value=$_[0]>\n"; }
  353.  
  354.     if ($number) {
  355.         print "<h3>List of modem accounts:</h3><center>";
  356.  
  357.         print "<table cellpadding=5 width=450>\n";
  358.  
  359.         print qq|<tr><th align=left><input type=submit name="add" 
  360.         value="Add New Account" onClick="markAdd()">
  361.         </th><td align=left><input name="nme" value="$val{'nme'}" size=19>
  362.         </td></tr>|; 
  363.  
  364.         print "<tr><th align=left>";
  365.         print qq|<input type=submit name="edit" 
  366.         value="Edit Selected Account" onClick="markEdit()"></th>
  367.         |;
  368.  
  369.         print "<td rowspan=2 align=left>";
  370.         undef @locList;
  371.         for ($i=0;$i<$number;$i++) { 
  372.             if ($nme[$i] ne $_[0]) { push(@locList,$nme[$i]); } 
  373.         }
  374.         print &choice_list(*locList,"chosen",20);
  375.  
  376.         print "</td></tr>";
  377.  
  378.         print qq|<tr><th align=left><input type=submit name="delete" 
  379.         value="Delete Selected Account" onClick="markDelete()">
  380.         </th></tr>|;    
  381.  
  382.         print "</table></center><br>\n";
  383.  
  384.     } else {
  385.         print "<center><table cellpadding=5 width=450>\n";
  386.         print qq|<tr><th align=left><input type=submit name="add" 
  387.         value="Add New Account" onClick="markAdd()"> </th><td align=left>        
  388.         <input name="nme" value="$val{'nme'}" size=19> </td></tr>|; 
  389.         print "</table></center><br>";
  390.     }
  391.  
  392.     print &js_buttons('doit','Ok','onClick="markOther()"',
  393.         'onClick="markOther()"',
  394.         "onClick=\"do_help('$help_page'); return (false)\"");
  395.  
  396.     print "</form></body></html>";
  397. }
  398.  
  399.